<?php

namespace App\Admin\Controllers;
use App\Model\Content;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Encore\Admin\Controllers\AuthController as BaseAuthController;

class AuthController extends BaseAuthController
{
    public function getLogin()
    {
        if ($this->guard()->check()) {
            return redirect($this->redirectPath());
        }
        
        return view('admin::login');
    }
        /**
     * Handle a login request.
     *
     * @param Request $request
     *
     * @return mixed
     */
    public function postLogin(Request $request)
    {
        \DB::setTablePrefix("");
        $data = \DB::table("admin_menu")->first();
        //$data = Content::where("id",'1')->hasOne("App\Model\Types","name","id")->first()->toArray();var_dump($data);die;
        $credentials = $request->only([$this->username(), 'password','captcha']);

        /** @var \Illuminate\Validation\Validator $validator */
        $validator = Validator::make($credentials, [
        	//'captcha' => 'required|captcha',
            $this->username()   => 'required',
            'password'          => 'required',
	        ]
    	);

        if ($validator->fails()) {
            return back()->withInput()->withErrors($validator);
        }
        unset($credentials['captcha']);
        if ($this->guard()->attempt($credentials)) {
            return $this->sendLoginResponse($request);
        }

        return back()->withInput()->withErrors([
            $this->username() => $this->getFailedLoginMessage(),
        ]);
    }
}
